#include "StdAfx.h"
#include "GDILibrary.h"
#include <GdiplusGraphics.h>


GDILibrary::GDILibrary(HWND winHandle)
{
	_handle = winHandle;
}


GDILibrary::~GDILibrary(void)
{
}
void GDILibrary::DrawLine(int x1, int y1, int x2, int y2, COLORREF color, int strokewidth)
{
	GdiplusStartupInput gdiplusStartupInput;
	ULONG_PTR gdiplusToken;
	GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
	Graphics g(_handle);
	g.DrawLine(new Pen(Color(GetRValue(color),GetGValue(color),GetBValue(color)), strokewidth), x1,y1,x2,y2);
	//GdiplusShutdown(gdiplusToken);
}

void GDILibrary::DrawRectangle(int x, int y, int width, int height, COLORREF color, int strokewidth, COLORREF fill)
{
	GdiplusStartupInput gdiplusStartupInput;
	ULONG_PTR gdiplusToken;
	GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
	Graphics g(_handle);
	if(strokewidth == 1)
		strokewidth++;
	g.DrawRectangle(new Pen(Color(GetRValue(color),GetGValue(color),GetBValue(color)), strokewidth), x, y, width, height);
	g.FillRectangle(new SolidBrush(Color(GetRValue(fill),GetGValue(fill),GetBValue(fill))), x, y, width, height);
	
	//GdiplusShutdown(gdiplusToken);
}
void GDILibrary::DrawEllipse(int cx, int cy, int rx, int ry, COLORREF color, int strokewidth, COLORREF fill)
{
	GdiplusStartupInput gdiplusStartupInput;
	ULONG_PTR gdiplusToken;
	GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
	Graphics g(_handle);
	g.DrawEllipse(new Pen(Color(GetRValue(color),GetGValue(color),GetBValue(color)), strokewidth), cx - rx, cy - ry, rx*2, ry*2);
	g.FillEllipse(new SolidBrush(Color(GetRValue(fill),GetGValue(fill),GetBValue(fill))), cx - rx, cy - ry, rx*2, ry*2);
	//GdiplusShutdown(gdiplusToken);
}

IGraphicLibrary* GDILibrary::Clone()
{
	return new GDILibrary(this->_handle);	
}
